﻿using System;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;

namespace Stee.Cap8.Service
{
    public class GrpcHealthService : GrpcHealth.GrpcHealthBase
    {
        private readonly ILogger<GrpcHealthService> _logger;
        public GrpcHealthService(ILogger<GrpcHealthService> logger)
        {
            _logger = logger;
        }

        public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context)
        {
            return Task.FromResult(new HealthCheckResponse
            {
                Status = GrpcServiceContext.IsReady() ? HealthCheckResponse.Types.ServingStatus.Serving :
                HealthCheckResponse.Types.ServingStatus.NotServing
            }); ;
        }

        public override Task<ModeCheckResponse> IsDegraded(ModeCheckRequest request, ServerCallContext context)
        {
            return Task.FromResult(new ModeCheckResponse
            {
                Status = GrpcServiceContext.IsDegraded() ? ModeCheckResponse.Types.ModeStatus.Degraded :
                ModeCheckResponse.Types.ModeStatus.Normal
            });
        }
    }
}
